﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SetupLauncher.Domain.Util;

namespace SetupLauncher.Domain.Logic.Environment
{
    internal class PreparePSE : IPrepareCommand
    {
        Logger.ILoggable _log;

        public PreparePSE(Logger.ILoggable log) 
        {
            _log = log;
        }

        public void Execute()
        {
            try
            {
                List<string> commands = new List<string>();

                commands.Add(@"del c:\windows\assembly\boost_thread-vc80-mt-1_39.dll");
                commands.Add(@"del c:\windows\assembly\FileHelpers.Common.Converters.dll");
                commands.Add(@"del c:\windows\assembly\FileHelpers.Common.dll");
                commands.Add(@"del c:\windows\assembly\FileHelpers.dll");
                commands.Add(@"del c:\windows\assembly\FileHelpers.ExcelStorage.dll");
                commands.Add(@"del c:\windows\assembly\Interop.mscoree.dll");
                commands.Add(@"del c:\windows\assembly\Interop.STMCom.dll");
                commands.Add(@"del c:\windows\assembly\Ionic.Zip.dll");
                commands.Add(@"del c:\windows\assembly\Microsoft.Practices.EnterpriseLibrary.Caching.dll");
                commands.Add(@"del c:\windows\assembly\Microsoft.Practices.EnterpriseLibrary.Common.dll");
                commands.Add(@"del c:\windows\assembly\Microsoft.Practices.EnterpriseLibrary.Data.dll");
                commands.Add(@"del c:\windows\assembly\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll");
                commands.Add(@"del c:\windows\assembly\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.dll");
                commands.Add(@"del c:\windows\assembly\Microsoft.Practices.EnterpriseLibrary.Logging.dll");
                commands.Add(@"del c:\windows\assembly\Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll");
                commands.Add(@"del c:\windows\assembly\Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design.dll");
                commands.Add(@"del c:\windows\assembly\Microsoft.Practices.EnterpriseLibrary.Validation.dll");
                commands.Add(@"del c:\windows\assembly\Microsoft.Practices.ObjectBuilder.dll");
                commands.Add(@"del c:\windows\assembly\NativeExcel.dll");
                commands.Add(@"del c:\windows\assembly\quickfix_net.dll");
                commands.Add(@"del c:\windows\assembly\quickfix_net_messages.dll");
                commands.Add(@"del c:\windows\assembly\TGP.MensageriaCliente.dll");
                commands.Add(@"del c:\windows\assembly\TGPClienteRemoto.dll");
                commands.Add(@"del c:\windows\assembly\TGPExecutorNet.dll");
                commands.Add(@"del c:\windows\assembly\TGPInterfaceParam.dll");
                commands.Add(@"del c:\windows\assembly\TGPMensagemNet.dll");
                commands.Add(@"del c:\windows\assembly\Xceed.Wpf.Controls.dll");
                commands.Add(@"del c:\windows\assembly\Xceed.Wpf.DataGrid.dll");

                string data = DateTime.Now.ToString("ddMMyyyyhhmmss");
                commands.Add(@"rename C:\DSEPROJ\Compilados\PSE PSE_old_" + data);

                foreach (string command in commands)
                {
                    WriteLog("Executando o comando: " + command);
                    DOSCommand.Execute(command);
                }

            }
            catch (Exception ex)
            {
                WriteException(ex.Message);
                throw ex;
            }
        }

        private void WriteLog(string message)
        {
            if (_log == null)
                return;
            _log.Write(message);
        }

        private void WriteException(string message)
        {
            if (_log == null)
                return;
            _log.WriteException(message);
        }
    }
}
